package com.wxl.common.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.wxl.common.bean.BatteryBean
import com.wxl.common.life.LifecycleManager

class BatteryReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
        val current = intent!!.extras!!.getInt("level") // 获得当前电量

        val total = intent.extras!!.getInt("scale") // 获得总电量

        val percent = current * 100 / total

        val batteryBean = BatteryBean()
        batteryBean.current = current
        batteryBean.percent  = percent
        batteryBean.total = total

        LifecycleManager.manager.postLiveData(batteryBean)
    }
}